package com.lmiot.xyclick.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.google.gson.Gson;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.XyNoticBean;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Util.DataUtil;
import com.lmiot.xyclick.Util.FileUtils;
import com.lmiot.xyclick.Util.LayoutDialogUtil;
import com.lmiot.xyclick.Util.LogUtil;
import com.lmiot.xyclick.Util.PhoneUtil;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.View.TitleBarView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.callback.FileCallBack;
import java.io.File;
import java.util.List;
import okhttp3.Call;

public class DenyActivity extends BaseActivity {
    private static final String TAG = "DenyActivity";
    private List<XyNoticBean.DenylistBean> mDenylist;
    TextView mIdEmpty;
    ListView mIdListview;
    private TitleBarView mIdTitleBar;

    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_deny);
        initView();
        this.mIdTitleBar.setOnItemClickListener(new TitleBarView.onItemClickListener() {
            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onTitleClick(View view) {
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onBackClick(View view) {
                DenyActivity.this.finish();
            }

            @Override // com.youyi.yyviewsdklibrary.View.TitleBarView.onItemClickListener
            public void onMenuClick(View view) {
                LayoutDialogUtil.showSureDialog(DenyActivity.this, "增加指引", "为核验准确性，您需要准备以下资料：\n1.需要保护的APP包名；\n2.需要保护的APP软著图片；\n\n资料准备好后，发送到以下邮件：\n809202631@qq.com\n我们收到邮件后，将在72个工作时内进行处理。如果因为特殊原因，无法提供软著的，也可联系我们处理哦！", true, false, "取消", "发送邮件", new LayoutDialogUtil.OnResultClickListener() {
                    /* class com.lmiot.xyclick.Activity.DenyActivity.AnonymousClass1.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.Util.LayoutDialogUtil.OnResultClickListener
                    public void result(boolean z) {
                        if (z) {
                            DenyActivity.this.sendMail();
                        }
                    }
                });
            }
        });
        downNotic();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendMail() {
        try {
            String str = DataUtil.getVip(MyApp.getContext()) ? "V" : "";
            Intent intent = new Intent("android.intent.action.SENDTO");
            intent.setData(Uri.parse("mailto:809202631@qq.com"));
            intent.putExtra("android.intent.extra.SUBJECT", getString(R.string.bmd) + PhoneUtil.getAPPVersion());
            intent.putExtra("android.intent.extra.TEXT", getString(R.string.pbb) + PhoneUtil.getBrand() + "\n" + getString(R.string.pdn) + PhoneUtil.getModel() + "\n【手机版本】: Android" + PhoneUtil.getSystemVersion() + str + "\n【用户信息】:" + PhoneUtil.getIMEI(MyApp.getContext()) + "\n" + getString(R.string.qsn));
            startActivity(intent);
        } catch (Exception e) {
            ToastUtil.warning(getString(R.string.pnsp));
            e.printStackTrace();
        }
    }

    private void downNotic() {
        File filesDir = MyApp.getContext().getFilesDir();
        LogUtil.d(TAG, "https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/noticText.txt");
        ((GetBuilder) OkHttpUtils.get().url("https://ai.xiaoyizhineng.com:441/download/HelpVideo/autoclick/noticText.txt")).build().execute(new FileCallBack(filesDir.getAbsolutePath(), "nt.xy") {
            @Override
            public void onError(Call call, Exception e, int id) {
                DenyActivity.this.mIdEmpty.setVisibility(View.VISIBLE);
                DenyActivity.this.mIdListview.setVisibility(View.GONE);
            }

            @Override
            public void onResponse(File file, int id) {
                if (file != null) {
                    XyNoticBean xyNoticBean = (XyNoticBean) new Gson().fromJson(FileUtils.readFileToString(file), XyNoticBean.class);
                    if (xyNoticBean != null) {
                        DenyActivity.this.mDenylist = xyNoticBean.getDenylist();
                        DenyActivity denyActivity = DenyActivity.this;
                        denyActivity.saveDenyList(denyActivity.mDenylist);
                    }
                }
                DenyActivity.this.showListView();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void saveDenyList(List<XyNoticBean.DenylistBean> list) {
        if (list != null && list.size() > 0) {
            StringBuffer stringBuffer = new StringBuffer();
            for (XyNoticBean.DenylistBean denylistBean : list) {
                stringBuffer.append(denylistBean.getPackName());
            }
            DataUtil.setDenyList(MyApp.getContext(), stringBuffer.toString().trim());
        }
    }

    @Override // android.support.v4.app.FragmentActivity, com.lmiot.xyclick.Activity.BaseActivity
    public void onResume() {
        super.onResume();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showListView() {
        if (this.mDenylist != null) {
            this.mIdEmpty.setVisibility(View.GONE);
            this.mIdListview.setVisibility(View.VISIBLE);
            this.mIdListview.setAdapter((ListAdapter) new DenyAdapter());
            return;
        }
        this.mIdEmpty.setVisibility(View.VISIBLE);
        this.mIdListview.setVisibility(View.GONE);
    }

    private void initView() {
        this.mIdTitleBar = (TitleBarView) findViewById(R.id.id_title_bar);
        this.mIdEmpty = (TextView) findViewById(R.id.id_empty);
        this.mIdListview = (ListView) findViewById(R.id.id_listview);
    }

    /* access modifiers changed from: private */
    public class DenyAdapter extends BaseAdapter {
        public Object getItem(int i) {
            return null;
        }

        public long getItemId(int i) {
            return 0;
        }

        private DenyAdapter() {
        }

        public int getCount() {
            return DenyActivity.this.mDenylist.size();
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate = View.inflate(DenyActivity.this, R.layout.item_deny, null);
            XyNoticBean.DenylistBean denylistBean = (XyNoticBean.DenylistBean) DenyActivity.this.mDenylist.get(i);
            ((TextView) inflate.findViewById(R.id.id_name)).setText(denylistBean.getName());
            String replaceAll = denylistBean.getPackName().replaceAll("1", "");
            ((TextView) inflate.findViewById(R.id.id_detail)).setText("包名：" + replaceAll);
            return inflate;
        }
    }
}
